# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def deleteNode(self, head: ListNode, val: int) -> ListNode:
        if head.val == val:
            return head.next
        cur_node = head
        while cur_node.next.val != val:
            cur_node = cur_node.next
        cur_node.next = cur_node.next.next
        return head